﻿Imports System.IO
Imports System.Net
Imports System.Text

Public Class HttpHelper

    Public Function HttpGet(Url As String, postDataStr As String) As String
        Dim request As HttpWebRequest = WebRequest.Create(Url + postDataStr)
        request.Method = "GET"
        request.ContentType = "text/html;charset=UTF-8"

        Dim response As HttpWebResponse = request.GetResponse()
        Dim myResponseStream As Stream = response.GetResponseStream()
        Dim myStreamReader As StreamReader = New StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"))
        Dim retString As String = myStreamReader.ReadToEnd()
        myStreamReader.Close()
        myResponseStream.Close()

        Return retString
    End Function

    Public Function HttpPost(Url As String, postDataStr As String) As String
        Dim request As HttpWebRequest = WebRequest.Create(Url)
        request.Method = "POST"
        request.ContentType = "application/x-www-form-urlencoded"
        request.ContentLength = Encoding.UTF8.GetByteCount(postDataStr)
        Dim myRequestStream As Stream = request.GetRequestStream()
        Dim myStreamWriter As StreamWriter = New StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"))
        myStreamWriter.Write(postDataStr)
        myStreamWriter.Close()

        Dim response As HttpWebResponse = request.GetResponse()

        Dim myResponseStream As Stream = response.GetResponseStream()
        Dim myStreamReader As StreamReader = New StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"))
        Dim retString As String = myStreamReader.ReadToEnd()
        myStreamReader.Close()
        myResponseStream.Close()

        Return retString
    End Function

End Class
